<template>
    <view :class="theme_view">
        <view v-if="(goods || null) != null">
            <form @submit="form_submit" class="form-container">
                <view class="page-bottom-fixed padding-main">
					<view class="status-tips padding-main bg-white border-radius-main spacing-mb">
						<view class="cr-red">
							当前发布频道：{{ goods.name }}<text v-if="((params.resend || null) != null && params.resend == 1)" style="margin-left:15rpx;">（您当前是重发消息，这意味着您将要发一条新的消息，若有涉及到发布信息的费用与正常发消息一致）</text>
						</view>
					</view>
                    <view v-if="goods.is_open_address == 1" class="bg-white border-radius-main pr oh spacing-mb padding-main">
						<view class="plugins-yxformplus">
							<view class="item" >
								<view class="title">信息所属地<text v-if="goods.is_open_address_strong == 1" class="cr-red text-size-xs margin-left-sm">*</text></view>
								<view class="spec spec2">
									<view class="flex-row jc-sb br-b-f5 padding-vertical-sm pr">
									    <view class="flex-1 flex-width flex-col">
									        <view v-if="goods.is_open_address_location == 1" @tap="choose_user_location_event" class="flex-row jc-sb align-c">
									            <view v-if="goods.is_open_address_location == 1" class="cr-main" @tap="choose_user_location_event">请先选择定位，再手动校正位置</view>
									            <iconfont name="icon-location" size="28rpx"></iconfont>
									        </view> 
									        <block>
									            <view class="flex-row align-c" :class="goods.is_open_address_location == 1 ? 'br-t-dashed padding-top-sm margin-top-sm' : ''">
									                <view class="flex-1 flex-width">
									                    <view @tap="open_ragion" class="single-text">
									                        <text v-if="province_name"> {{ province_name }}{{ city_name ? '-' + city_name : '' }}{{ county_name ? '-' + county_name : '' }} </text>
									                        <text v-else class="cr-grey-9">{{$t('extraction-apply.extraction-apply.cy87k6')}}</text>
									                    </view>
														<component-region-picker :propProvinceId="province_id" :propCityId="city_id" :propCountyId="county_id" :propShow="region_picker_show" @onclose="close_event" @callBackEvent="region_event"></component-region-picker>
									                </view>
									            </view>
									        </block>
									    </view>
									</view>
									<view class="flex-row jc-sb align-c br-b-f5 padding-vertical-sm">
									    <view class="flex-1 flex-width">
									        <input type="text" name="address" :value="address_data.address || ''" maxlength="80" placeholder-class="cr-grey-9" :class="'cr-base bs-bb ' + (goods.is_open_address_location == 1 ? 'address-value' : '')" :placeholder="$t('user-address-save.user-address-save.vdkv32')" @blur="yxblur" />
									    </view>
									</view>
									<view v-if="locationInfo" class="cr-main" style="font-size: 24rpx; margin-top: 10rpx;">
										{{ locationInfo }}
									</view>
								</view>
							</view>
						</view>
					</view>
					<view class="bg-white border-radius-main pr oh spacing-mb padding-main">
                        <view class="goods-spec-choose plugins-yxformplus">
                        	<view class="item flex-row">
                        		<view class="title"><text v-if="goods.is_title_strong == 1" class="cr-red text-size-xs margin-right-sm">*</text><text v-else class="cr-white text-size-xs margin-right-sm">*</text>信息标题</view>
                        		<view class="spec flex-1">
									<input type="text" placeholder-class="cr-grey-9" placeholder="请输入信息标题" name="title" class="form-item wh-auto yxformplus-item" :value="data.title || ''" maxlength="260" />
								</view>
							</view>
						</view>
					</view>
					<!-- 自定义独立表单数据展示 -->
					<view v-if="(goods.field_list || null) != null && goods.field_list.length > 0" class="padding-main border-radius-main bg-white spacing-mb">
						<view v-if="info_id > 0"><text class="cr-red text-size-xs">请注意，编辑下面的信息将会实时更改，而无须点击提交按钮！</text></view>
						<component-tj-form ref="tjform" :propData="goods.field_list" :propEditorPath="editor_path_type" :propGoodsId="info_id" propFormType="classinfo" :propUrl="field_save_url" @backtoupdate="backtoupdate"></component-tj-form>
					</view>

					<view class="bg-white border-radius-main pr oh spacing-mb padding-main">
						<view class="plugins-yxformplus">
							<view class="item flex-row">
								<view class="title"><text class="cr-red text-size-xs margin-right-sm">*</text>{{goods.ms_title}}</view>
								<view class="spec spec2 flex-1">
									<textarea :placeholder="goods.ms_desc || '请输入'+goods.ms_title+'，长度不超过10000'" name="content" placeholder-class="cr-grey-9" class="form-item wh-auto yxformplus-item" maxlength="100000" :value="data.content || ''"></textarea>
								</view>
							</view>
							<view class="item flex-row" v-if="(goods.label_arr || null) != null">
								<view class="title"><text class="cr-white text-size-xs margin-right-sm">*</text>标签</view>
								<view class="spec flex-1">
									<view v-if="(goods.label_arr || null) != null" class="label_box">
										<view class="label_box_cc">
											<block v-for="(item, index) in goods.label_arr" :key="index">
												<view :data-index="index" class="fl text-size-xs br-main" :class="(label_arr_chose[index] ? 'bg-main cr-white' : '')" @tap="label_event">{{item}}</view>
											</block>
										</view>
										<view class="c_b"></view>
									</view>
								</view>
							</view>
							<view class="item flex-row">
								<view class="title" style="margin-bottom:20rpx;"><text class="cr-white text-size-xs margin-right-sm">*</text>信息图片</view>
								<view class="spec spec2 flex-1">
									<component-upload :propData="image_list" propMaxNum="9" propDelServ="yes" :propDelServUrl="del_serv_url" :propPathType="editor_path_type" @call-back="retrun_image_event"></component-upload>
								</view>
							</view>
							<view class="item flex-row">
								<view class="title"><text class="cr-white text-size-xs margin-right-sm">*</text>截止时间</view>
								<view class="spec flex-1">
									<picker mode="date" :value="(data.over_time || null) != null ? data.over_time : 0" @change="bindDateChange">
										<view v-if="(data.over_time_text || null) != null && data.over_time_text != ''" class="tj-input cr-grey">{{data.over_time_text}}<text class="arrow-right cr-grey padding-left"></text></view>
										<view v-else class="tj-input cr-grey">{{$t('fengcheche.serv.laoban.pleasechose')}}<text class="arrow-right cr-grey padding-left"></text></view>
									</picker>
									<view class="cr-grey-9">这里选择你发布的任务的截止时间，若无必要，可以不选</view>
								</view>
							</view>
							<block v-if="goods.is_close_contact != 1">
								<view class="item flex-row">
									<view class="title"><text v-if="goods.is_close_contact != 1" class="cr-red text-size-xs margin-right-sm">*</text><text v-else class="cr-white text-size-xs margin-right-sm">*</text>联系人</view>
									<view class="spec flex-1">
										<input type="text" placeholder-class="cr-grey-9" placeholder="输入联系人" name="contact_name" class="form-item wh-auto yxformplus-item" :value="data.contact_name || (((user || null) != null && (user.truename || null) != null) ? user.truename : '')" maxlength="30" />
									</view>
								</view>
								<view class="item flex-row">
									<view class="title"><text v-if="goods.is_close_contact != 1" class="cr-red text-size-xs margin-right-sm">*</text><text v-else class="cr-white text-size-xs margin-right-sm">*</text>电话</view>
									<view class="spec flex-1">
										<input type="text" placeholder-class="cr-grey-9" placeholder="输入联系人电话" name="contact_tel" class="form-item wh-auto yxformplus-item" :value="data.contact_tel || (((user || null) != null && user.mobile != '') ? user.mobile : '')" maxlength="20" />
									</view>
								</view>
							</block>
						</view>
                    </view>
					
					<!--选择有效期，如果是按天计费模式下-->
					<view v-if="goods.is_price == 1 && goods.fee_type == 1 && (goods.day_price_arr || null) != null && goods.day_price_arr.length > 0 && info_id == 0" class="padding-main border-radius-main bg-white spacing-mb">
						<view class="plugins-yxformplus">
							<view><text class="cr-red text-size-xs">请注意，有效期仅在发布时进行选择，是不可通过编辑来改变的，后期需通过刷新功能来延长到期时间！</text></view>
							<view v-if="(goods.is_show_long_time || null) != null && goods.is_show_long_time == 1" class="item flex-row">
								<view class="title"><text class="cr-red text-size-xs margin-right-sm">*</text>信息有效期</view>
								<view class="spec spec2 flex-1">
									<view class="uni-list">
										<radio-group @change="yxonclick">
											<label class="yxradio" v-for="(items, indexs) in goods.day_price_arr" :key="indexs">
												<radio :value="indexs" :checked="items.checked != ''" :color="theme_color" name="day_price" style="transform:scale(0.7);" />{{items.day_text}}
											</label>
										</radio-group>
									</view>
								</view>
							</view>
							<view class="item flex-row">
								<view class="title cr-red"><text class="cr-red text-size-xs margin-right-sm">*</text>发布价格</view>
								<view class="spec flex-1">
									<view v-if="(free_info || null) != null && (free_info.youhui || null) != null && free_info.youhui.length > 0" class="fabu_price_box cr-red">
										<text class="t1">{{currency_symbol}}</text>
										<block v-for="(items, indexs) in goods.day_price_arr" :key="indexs" >
											<text v-if="day_price_index == indexs" class="t2">{{items.price - free_info.youhui[indexs]}}</text>
										</block>
									</view>
									<view v-for="(items, indexs) in goods.day_price_arr" :key="indexs" class="fabu_price_box" :class="((free_info || null) != null && (free_info.youhui || null) != null && free_info.youhui.length > 0) ? 'original-price' : 'cr-red'">
										<block v-if="day_price_index == indexs">
											<text class="t1">{{currency_symbol}}</text>
											<text class="t2">{{items.price}}</text>
										</block>
									</view>
									<view v-if="(free_info || null) != null && (free_info.free_desc || null) != null && free_info.free_desc != ''" class="cr-red">
										<text class="t3">{{free_info.free_desc}}</text>
									</view>
								</view>
							</view>
						</view>
					</view> 
					<view v-if="goods.is_price == 1 && goods.fee_type == 0 && goods.price > 0 && info_id == 0" class="padding-main border-radius-main bg-white spacing-mb">
						<view class="plugins-yxformplus">
							<view class="item flex-row" v-if="(goods.is_show_long_time || null) != null && goods.is_show_long_time == 1">
								<view class="title"><text class="cr-red text-size-xs margin-right-sm">*</text>信息有效期</view>
								<view class="spec flex-1">
									<view class="fabu_price_box">
										<text v-if="goods.endtime_day > 0" class="t1">{{goods.endtime_day}}天</text>
										<text v-else class="t1">长期有效</text>
									</view>
								</view>
							</view>
							<view class="item flex-row">
								<view class="title cr-red"><text class="cr-red text-size-xs margin-right-sm">*</text>发布价格</view>
								<view class="spec flex-1">
									<view v-if="(free_info || null) != null && (free_info.youhui || null) != null && free_info.youhui.length > 0" class="fabu_price_box cr-red">
										<text class="t1">{{currency_symbol}}</text>
										<text class="t2">{{goods.price - free_info.youhui[0]}}</text>
									</view>
									<view class="fabu_price_box" :class="((free_info || null) != null && (free_info.youhui || null) != null && free_info.youhui.length > 0) ? 'original-price' : 'cr-red'">
										<text class="t1">{{currency_symbol}}</text>
										<text class="t2">{{goods.price}}</text>
									</view>
									<view v-if="(free_info || null) != null && (free_info.free_desc || null) != null && free_info.free_desc != ''" class="cr-red">
										<text class="t3">{{free_info.free_desc}}</text>
									</view>
								</view>
							</view>
						</view>
					</view>
					
					<!-- 魔方 - 插件 -->
					<block v-if="(plugins_fccprouniapp_mofang || null) != null">
						<component-mofang :propData="plugins_fccprouniapp_mofang" propLocation="21"></component-mofang>
					</block>

                    <view class="bg-white border-radius-main pr oh spacing-mb dis-none">
                        <view class="form-gorup">
                            <view class="flex-row jc-sb align-c">
                                <view class="form-gorup-title padding-right-main">阅读推广，让更多人看到</view>
                                <view class="flex-1 flex-width tr">
                                    <switch :color="theme_color" :checked="(data.is_enable || 0) == 1 ? true : false" @change="is_enable_event" />
                                </view>
                            </view>
                        </view>
                    </view>

                    <view class="spacing-mb spacing-mt">
						<!-- 协议 -->
						<view class="cr-grey">
							<view class="dis-inline-block va-m" @tap="agreement_change">
								<radio-group class="dis-inline-block va-m" style="transform:scale(0.6)">
									<label>
										<radio value="agreement" :color="theme_color" :checked="agreement_status" />
									</label>
								</radio-group>
							</view>
							<view class="dis-inline-block va-m">
								<text>阅读并同意 </text>《<text class="cr-main" @tap="popup_xieyi_event">用户协议</text>》，保证信息合法合规
							</view>
						</view>
                    </view>
                </view>
                <!-- 底部操作 -->
                <view class="bottom-fixed btn-bottom bg-white">
                    <view class="oh bottom-line-exclude">
                        <button class="cr-white bg-main round text-size wh-auto" type="default" form-type="submit" hover-class="none" :loading="form_submit_loading" :disabled="form_submit_loading">{{$t('common.submit')}}</button>
                    </view>
                </view>
                <component-popup :propShow="popup_status" propPosition="bottom" @onclose="popup_close_event">
                    <view class="p-title flex-row jc-sb align-c padding-main br-b-e">
                        <view class="text-size-lg fw-b">{{$t('form.form.4vku7u')}}</view>
                        <view class="popup-colse" @tap="popup_close_event">
                            <iconfont name="icon-close-line" color="#333" size="28rpx"></iconfont>
                        </view>
                    </view>
                    <view class="p-content padding-main">
                        <view v-for="(item, index) in classinfo_category_list" :key="index">
                            <view class="padding-vertical-main flex-row jc-sb align-c" :class="data.classinfo_category_id == item.id ? 'cr-main' : ''" :data-value="item.name" :data-id="item.id" @tap="get_type_event">
                                {{ item.name }}
                                <iconfont v-if="data.classinfo_category_id === item.id" name="icon-checked" color="#333" size="28rpx"></iconfont>
                            </view>
                        </view>
                    </view>
                </component-popup>
            </form>
			<!-- 协议弹层 -->
			<component-popup :propShow="popup_xieyi_status" propPosition="bottom" @onclose="popup_xieyi_close_event">
			    <view class="padding-horizontal-main padding-top-main bg-white">
			        <view class="close oh">
			            <view class="fr" @tap.stop="popup_xieyi_close_event">
			                <icon type="clear" size="20"></icon>
			            </view>
			        </view>
			        <view class="plugins-xieyi-container padding-bottom-main">
			            <view v-if="xieyi.length > 0">
			            	<view class="goods-parameters bg-white">
			            		<view class="content-item">
									<view class="bigtit">用户协议</view>
			            			<block v-for="(item, index) in xieyi" :key="index">
			            				<view class="item">
			            					<text class="value">{{item}}</text>
			            				</view>
			            			</block>
			            		</view>
			            	</view>
			            </view>
			        </view>
					<button class="goods-popup-submit cr-white bg-main" type="default" @tap="xieyi_enter_confirm_event" hover-class="none">同意该协议</button>
			    </view>
			</component-popup>

        </view>
        <view v-else>
            <!-- 提示信息 -->
            <component-no-data :propStatus="data_list_loding_status" :propMsg="data_list_loding_msg"></component-no-data>
        </view>
		
		<!-- 位置选择 -->
		<component-choice-location ref="choice_location" :propIsShowAddressChoice="false" @onBack="user_back_choice_location"></component-choice-location>
		
		<!-- 支付弹窗 :diyTheme="diytheme"-->
		<component-payment  
		    :propCurrencySymbol="currency_symbol"
		    :propPayUrl="pay_url"
		    :propQrcodeUrl="qrcode_url"
		    propPayDataKey="ids"
		    :propPaymentList="payment_list"
		    :propTempPayValue="temp_pay_value"
		    :propPayPrice="pay_price"
		    :propPaymentId="payment_id"
		    :propIsRedirectTo="true"
		    :propToFailPage="to_fail_page"
		    :propToAppointPage="to_appoint_page"
		    :propIsShowPayment="is_show_payment_popup"
		    @close-payment-popup="payment_popup_event_close"
		></component-payment>
    </view>
</template>
<script>
    const app = getApp();
	// #ifdef APP-PLUS
	import ykAuthpup from "@/components/yk-authpup/yk-authpup";
	// #endif
    import componentPopup from '@/components/popup/popup';
    import componentUpload from '@/components/upload/upload';
    import componentNoData from '@/components/no-data/no-data';
	import componentRegionPicker from '@/pages/common/components/region-picker/region-picker';
	import componentChoiceLocation from '@/components/choice-location/choice-location';
	import componentPayment from '@/components/payment/payment';
	import componentMofang from "@/components/mofang/mofang";
	import componentTjForm from "../public/tj-form-uv/tj-form-uv";
    export default {
        data() {
            return {
                theme_view: app.globalData.get_theme_value_view(),
                theme_color: app.globalData.get_theme_color(),
                data_list_loding_status: 1,
				data_list_loding_msg: '',
                data: {},
                index: 0,
				params:null,
				goods:null,
				category:null,
				label_arr_chose:[],
				config: null,
				info_id: 0,
				user: null,

                // 分类选择弹窗
                popup_status: false,
                classinfo_category_list: [],

                // 封面图片
                image_list: [],
                // 路径类型
                editor_path_type: 'common',
				del_serv_url: app.globalData.get_request_url("deleteimg", "info", "classinfo"),
				field_save_url: app.globalData.get_request_url("fieldsave", "yxfield", "classinfo"),

                // 内容
                input_length_max: 500,
                input_value: '',
                // 查看更多
                more_height: '0',
                is_more: false,

                // 提交按钮
                form_submit_loading: false,
				popup_xieyi_status:false,
				xieyi: [],
				permissionID:'',
				day_price_index: 0,
				
				address_data: {},
				// id
				province_id: null,
				city_id: null,
				county_id: null,
				// name
				province_name: '',
				city_name: '',
				county_name: '',
				// 已选择的信息所在地
				locationInfo: '',

				// 多列选择器
				region_picker_show: false,
				
				// 自定义表单插件
				user_location_cache_key: app.globalData.data.cache_userlocation_key,
				check_result:[],
				plugins_yxformplus_single_data: null,
				plugins_yxformplus_single_form_id_str: '',
				currency_symbol: app.globalData.currency_symbol(),
				
				// 支付弹窗参数
				pay_url: app.globalData.get_request_url('pay', 'index', 'classinfo'),
				qrcode_url: app.globalData.get_request_url('paycheck', 'index', 'classinfo'),
				payment_list: [],
				temp_pay_value: '',
				is_show_payment_popup: false,
				pay_price: 0,
				payment_id: 0,
				// 支付失败跳转的页面
				to_fail_page: '/pages/fcc/classinfo/user-list/user-list',
				to_appoint_page: '/pages/fcc/classinfo/user-list/user-list',
				
				diytheme: app.globalData.get_fcc_theme_color(),
				free_info: null,
				is_user_address_discern: 0,
				over_time: '',
				agreement_status: false,
				plugins_fccprouniapp_mofang: null,
            };
        },
        components: {
			// #ifdef APP-PLUS
			ykAuthpup,
			// #endif
            componentPopup,
            componentUpload,
            componentNoData,
			componentRegionPicker,
			componentChoiceLocation,
			componentTjForm,
			componentPayment,
			componentMofang
        },

        onLoad(params) {
            //params['gid'] = 9;
            this.setData({
                params: params,
				info_id: params.id || 0
            });

            // 数据加载
            this.init();
        },

        onShow() {
			app.globalData.page_event_onshow_handle();
		},

        // 下拉刷新
        onPullDownRefresh() {},

        // 页面销毁时执行
        onUnload: function () {},

        methods: {
			label_event(e){
				var index = e.currentTarget.dataset.index;
				var temp_label_arr_chose = this.label_arr_chose;
				temp_label_arr_chose[index] = !temp_label_arr_chose[index];
				this.setData({
				    label_arr_chose: temp_label_arr_chose
				});
				// 存到缓存
				var temp = this.data;
				temp['label_arr_chose'] = this.label_arr_chose;
				uni.setStorageSync('plugins_classinfo_form_temp', temp);
			},
            init() {
                var user = app.globalData.get_user_info(this, 'init');
                if (user != false) {
					console.log(user);
					this.setData({
					    user: user
					});
                    this.get_data_list_before();
                } else {
                    // 提示错误
                    this.setData({
                        data_list_loding_status: 2,
                        data_list_loding_msg: this.$t('form.form.8l3ul5'),
                    });
                }
            },
			bindDateChange(e){//console.log(e);
				var value = e.detail.value;
				if(value != '')
				{
					var temp_data = this.data;
					temp_data.over_time_text = value;
					this.setData({
						data: temp_data,
					    over_time: value
					});
				}
			},
			get_data_list_before(){
				var self = this;
				// 赋值已有数据
				uni.getStorage({
					key: 'plugins_classinfo_form_temp',
					success: function (res) {
						self.setData({
						    data: res.data,
						});
					},
					complete: function (res) {
						self.get_data_list();
					}
				});
			},
            get_data_list() {
				var gid = this.params.gid || null;
				if(gid == null)
				{
					app.globalData.showToast('类型参数有误，请返回后重新选项发布');
					return false;
				}
				var id = this.info_id;
				
                // 加载loding
                uni.showLoading({
                    title: this.$t('common.loading_in_text'),
                });
				
				if(parseInt(id) > 0)
				{
					this.setData({
						data_list_loding_status: 1,
						field_save_url: app.globalData.get_request_url("fieldsavetrue", "yxfield", "classinfo"),
					});
				}else{
					this.setData({
					    data_list_loding_status: 1,
					});
				}
                uni.request({
                    url: app.globalData.get_request_url('fabuinit', 'info', 'classinfo'),
                    method: 'POST',
                    data: { gid: gid, id: id },
                    success: (res) => {
						//console.log('-------->fabuint');console.log(res);
                        uni.hideLoading();
                        if (res.data.code == 0) {
							var info = res.data.data;
							var goods = info.goods || null;
							var data = info.data || null;
							var temp_label_arr_chose = [];
							if((goods != null) && (goods.label_arr || null) != null)
							{
								let array_arr = (data || null) != null ? ((data.label_arr || null) != null ? data.label_arr : null) : null;
								for(var i in goods.label_arr)
								{
									if((array_arr || null) != null && array_arr.includes(goods.label_arr[i]))
									{
										temp_label_arr_chose[i] = true;
									}
									else{
										temp_label_arr_chose[i] = false;
									}
								}
							} 
							
							var temp_image_list =  (data || null) != null ? (data.images != '' ? data.images : []) : [];

							var upd_data = {
								data: data || {},
								goods: goods,
								config: info.config || null,
								category: info.category || null,
								payment_list: info.payment_list,
								payment_id: info.default_payment_id || 0,
								label_arr_chose: temp_label_arr_chose,
								xieyi: info.xieyi || [],
								data_list_loding_status: 3,
								editor_path_type: info.editor_path_type,
								image_list: temp_image_list,
							    province_id: (data != null) ? data.province : null,
							    city_id: (data != null) ? data.city : null,
							    county_id: (data != null) ? data.county : null,
							    city_name: (data != null) ? data.city_name : '',
							    province_name: (data != null) ? data.province_name : '',
							    county_name: (data != null) ? data.county_name : '',
								free_info: info.free_info || null,
								is_user_address_discern: app.globalData.get_config('plugins_base.intellectstools.data.is_user_address_discern', 0),
								plugins_fccprouniapp_mofang: info.mofang || null,
							};
							if(parseInt(id) > 0)
							{
								var day_price_index = parseInt(data.fee_type)-1;
								if(day_price_index < 0)
								{
									day_price_index = 0;
								}
								upd_data['day_price_index'] = day_price_index;
							}
							var temp_address = {};
							// 地址赋值 
							if(data != null)
							{
								var arr = ['province', 'city', 'county', 'province_name', 'city_name', 'county_name', 'address', 'lng', 'lat'];
								for(var i in arr) {
								    if((data[arr[i]] || null) != null) {
								        temp_address[arr[i]] = data[arr[i]];
								    }
								}
							}
							if((temp_address.lat || null) != null)
							{
								const locationInfo = `定位信息：${temp_address.address}, ${temp_address.lat}, ${temp_address.lng}`;
								this.locationInfo = locationInfo;
							}
							
							// 初始化时若有经纬度，则存入 
							upd_data['address_data'] = temp_address;
							this.setData(upd_data);
							//console.log(temp_address);
							// 存到缓存
							if((data || null) != null)
							{
								var temp = data;
								temp['image_list'] = temp_image_list;
								temp['label_arr_chose'] = this.label_arr_chose;
								uni.setStorageSync('plugins_classinfo_form_temp', temp);
							}
                        } else {
                            this.setData({
                                data_list_loding_status: 0,
								data_list_loding_msg: res.data.msg,
                            });
                            if (app.globalData.is_login_check(res.data, this, 'get_data_list')) {
                                app.globalData.showToast(res.data.msg);
                            }
                        }
                    },
                    fail: () => {
                        uni.hideLoading();
                        this.setData({
                            data_list_loding_status: 2,
							data_list_loding_msg: this.$t('common.internet_error_tips')
                        });
                        app.globalData.showToast(this.$t('common.internet_error_tips'));
                    },
                });
            },
            // 弹层打开
            popupOpen() {
                this.setData({
                    popup_status: true,
                });
            },

            // 弹层关闭
            popup_close_event(e) {
                this.setData({
                    popup_status: false,
                });
            },
			
			yxonclick(e)
			{
				var value = e.detail.value;
				this.setData({
				    day_price_index: value,
				});
			},

            // 是否启用
            is_enable_event(e) {
                var new_data = this.data;
                new_data.is_enable = e.detail.value ? 1 : 0;
                this.setData({
                    data: new_data,
                });
				// 存到缓存
				uni.setStorageSync('plugins_classinfo_form_temp', new_data);
            },

            // 获取选中的分类
            get_type_event(e) {
                var new_data = this.data;
                new_data.classinfo_category_id = e.currentTarget.dataset.id;
                new_data.classinfo_category_name = e.currentTarget.dataset.value;
                this.setData({
                    data: new_data,
                    popup_status: false,
                });
				// 存到缓存
				uni.setStorageSync('plugins_classinfo_form_temp', new_data);
            },

            // 上传回调
            retrun_image_event(data) {
                this.setData({
                    image_list: data,
                });
				// 存到缓存
				var temp = this.data;
				temp['image_list'] = this.image_list;
				uni.setStorageSync('plugins_classinfo_form_temp', temp);
            },

            // 回调富文本内容
            rich_text_event(e) {
                var new_data = this.data;
                new_data.content = e.html;
                this.setData({
                    data: new_data,
                });
				// 存到缓存
				uni.setStorageSync('plugins_classinfo_form_temp', new_data);
            },
            initEditor(editor) {
                // 初始化编辑器内容
                editor.setContents({
                    html: (this.data || null) !== null ? this.data.content : '',
                });
            },

            // 上传图片
            up_in_image_event(tempFiles, editorCtx) {
                var self = this;
                // 使用 uniCloud.uploadFile 上传图片的示例方法（可适用多选上传）
                tempFiles.forEach(async (item) => {
                    uni.showLoading({
                        title: self.$t('form.form.2e5rv3'),
                        mask: true,
                    });
                    await uni.uploadFile({
                        url: app.globalData.get_request_url('index', 'ueditor'),
                        // #ifdef APP-PLUS || H5
                        filePath: item.path,
                        // #endif
                        // #ifdef MP-WEIXIN
                        filePath: item.tempFilePath,
                        // #endif
                        name: 'upfile',
                        formData: {
                            action: 'uploadimage',
                            path_type: 'common', // 路径类型，默认common
                        },
                        success: function (res) {
                            let data = JSON.parse(res.data);
                            if (res.statusCode == 200) {
                                // 上传完成后处理
                                editorCtx.insertImage({
                                    src: data.data.url, // 此处需要将图片地址切换成服务器返回的真实图片地址
                                    // width: '50%',
                                    alt: self.$t('form.form.3h58hv'),
                                    success: function (e) {},
                                });
                                uni.hideLoading();
                            }
                        },
                        fail: function (e) {
                            app.globalData.showToast(e.errMsg);
                            uni.hideLoading();
                        },
                    });
                });
            },

            // 更多内容
            more_event() {
                this.setData({
                    more_height: !this.is_more ? '708rpx' : '0',
                    is_more: !this.is_more,
                });
            },
			
			// 子组件中数据保存后，刷新当前页面对应数据
			backtoupdate(data){
				//this.init();
				// 主要刷新表单数据
			},

            // 表单提交
            form_submit(e) {
				this.setData({
					check_result: []
				});
				
				// 校验表单
				var tjform = this.$refs.tjform || [];
				if (tjform.length > 0) {
					for (var i in tjform) {
						if (!tjform[i].datacheck()) {
							return false;
							break;
						}
					}
				}
				this.real_go_submit(e);
			},
			onSubmitone(backdata){
				if(this.form_submit_loading)
				{
					return false;
				}
				
				// 将每次的回调结果保存起来
				this.check_result.push(backdata);
				
				// 总字段数
				var form_num = 0;
				form_num = this.goods.field_list.length || 0;
				
				if(this.check_result.length == form_num)
				{
					var check_fail_num = 0;
					for (var i in this.check_result) {
						check_fail_num += parseInt(this.check_result[i]);
					}
							
					if(check_fail_num == 0)
					{
						this.real_go_submit();
					}
				}
			},
			real_go_submit(e){
				// 是否已同意协议
				if(!this.agreement_status) {
				    app.globalData.showToast('请先同意协议');
					this.popup_xieyi_event(e);
				    return false;
				}
				
				// 表单数据
				var form_data = e.detail.value;
				// 加入页面请求参数
				form_data['params'] = this.params;
				
                // 数据验证
                var validation = [
                    { fields: 'content', msg: '描述不能为空' },
                ];
				if(this.goods.is_close_contact != 1)
				{
					validation.push({fields: 'contact_name', msg: '联系人不能为空'});
					validation.push({fields: 'contact_tel', msg: '联系电话不能为空'});
				}
				if(this.goods.is_title_strong == 1)
				{
					validation.push({fields: 'title', msg: '标题必填'});
				}
				if(this.goods.is_open_address_strong == 1)
				{
					// 检验省市区地址
					validation.push({ fields: 'province', msg: this.$t('extraction-apply.extraction-apply.m99d2g') });
					validation.push({ fields: 'city', msg: this.$t('extraction-apply.extraction-apply.03587o') });
					// 区县不做强制，详细地址也不做强制
					
					// 经纬度要强制
					//validation.push({ fields: 'lng', msg: this.$t('buy.buy.3740ur') });
				}
				form_data['province'] = this.province_id;
				form_data['city'] = this.city_id;
				form_data['county'] = this.county_id;
				form_data['id'] = this.params.id || 0;
				
				// 默认地址信息
				var temp_ads = this.address_data || {};
				
				// 地理位置
				var lng = temp_ads.lng || 0;
				var lat = temp_ads.lat || 0;
				form_data['lng'] = lng;
				form_data['lat'] = lat;
				
				// 添加的时候提交信息有效期
				if(parseInt(form_data['id']) == 0)
				{
					if(this.goods.fee_type == 1)
					{
						form_data['fee_type'] = this.day_price_index;
					}else{
						form_data['fee_type'] = 0;
					}
				}
				
                if (app.globalData.fields_check(form_data, validation)) {
                    uni.showLoading({
                        title: this.$t('buy.buy.r79t77'),
                    });
                    this.setData({
                        form_submit_loading: true,
                    });
					
                    var new_data = {
						'gid': this.params.gid,
						'label_arr': this.goods.label_arr || [],
						'image_list': this.image_list,
						'label_arr_chose': this.label_arr_chose,
						'over_time': this.over_time,
                        ...form_data,
                    };
					console.log(new_data);
					
                    // 网络请求
                    uni.request({
                        url: app.globalData.get_request_url('save', 'info', 'classinfo'),
                        method: 'POST',
                        data: new_data,
                        dataType: 'json',
                        success: (res) => {
                            uni.hideLoading();
                            if (res.data.code == 0) {
								// 清理当前页面临时数据
								uni.removeStorageSync('plugins_classinfo_form_temp');
								
								// 添加的时候，返回判断是否得到了订单ID
								if (parseInt(form_data['id']) == 0 && (res.data.data || null) != null && res.data.data.order.status == 1) {
									uni.setStorageSync(app.globalData.data.cache_page_pay_key, { type: 1 });
									this.setData({
									    is_show_payment_popup: true,
									    pay_price: res.data.data.order.total_price,
									    temp_pay_value: res.data.data.order.id
									});
								} else {
									app.globalData.showToast(res.data.msg, 'success');
								    setTimeout(function () {
								    	// 回到我的信息页面
								    	app.globalData.url_open('/pages/fcc/classinfo/user-list/user-list');
								    }, 2000);
								}
                            } else {
                                this.setData({
                                    form_submit_loading: false,
                                });
                                if (app.globalData.is_login_check(res.data)) {
                                    app.globalData.showToast(res.data.msg);
                                } else {
                                    app.globalData.showToast(this.$t('common.sub_error_retry_tips'));
                                }
                            }
                        },
                        fail: () => {
                            uni.hideLoading();
                            this.setData({
                                form_submit_loading: false,
                            });
                            app.globalData.showToast(this.$t('common.internet_error_tips'));
                        },
                    });
                }
            },
			
			payment_popup_event_close() {
			    this.setData({
			        is_show_payment_popup: false,
					form_submit_loading: false
			    });
			},
			
			// 选择地理位置
			choose_user_location_event(e) {
			    if ((this.$refs.choice_location || null) != null) {
			        this.$refs.choice_location.choose_user_location();
			    }
			},
			
			// 清除位置缓存信息
			choose_user_location_remove() {
			    app.globalData.choice_user_location_remove();
			},
			
			// 选择用户地理位置回调
			user_back_choice_location(e) {
				console.log(e);
				/*
				address: "X省X市X区X街道行政大道6号区政府对面"
				is_user: 0
				lat: 38.116504
				lng: 111.059056
				name: "两云茶叶(X直营店)"
				status: 1
				text: "两云茶叶(X直营店)"
				*/
				var temp_address = this.address_data || {};
				
				// 将选择的经纬度带入地址数据中
				temp_address['lat'] = e.lat || null;
				temp_address['lng'] = e.lng || null;
				temp_address['address'] = e.name || '';// 只要选择定位，则改变详细地址
				
				// 如果现有的所在地地址数据中无详细地址，则这里将定位的地名当做详细地址存储起来
				/*if((temp_address.address || null) != null && temp_address.address != '')
				{
					// 若有详细地址，则不改变详细地址
				}else{
					temp_address['address'] = e.name || '';
				}*/
				this.setData({
					address_data: temp_address
				});
				
				const locationInfo = `定位信息：${e.name}, ${e.address}, ${e.lat}, ${e.lng}`;
				this.locationInfo = locationInfo;
				
				if(this.is_user_address_discern == 1)
				{
					this.address_discern_handle(e, 0, 1);
				}
			},

			// 地址识别处理
			// data 地址信息
			// is_user 是否解析用户信息（0, 1）
			// type 0 用户输入地址信息识别, 1用户选择地理位置识别
			address_discern_handle(data, is_user = 0, type = 0) {
			    data['is_user'] = is_user;
			    uni.showLoading({
			        title: this.$t('common.processing_in_text'),
			        mask: true,
			    });
			    uni.request({
			        url: app.globalData.get_request_url('address', 'index', 'intellectstools'),
			        method: 'POST',
			        data: data,
			        dataType: 'json',
			        success: (res) => {console.log(res);
			            uni.hideLoading();
			            if (res.data.code == 0) {
			                var temp_ads = this.address_data || {};
			                var ads_data = res.data.data;
			                var upd_data = {
			                    province_id: ads_data.province || null,
			                    city_id: ads_data.city || null,
			                    county_id: ads_data.county || null,
			                    city_name: ads_data.city_name || '',
			                    province_name: ads_data.province_name || '',
			                    county_name: ads_data.county_name || '',
			                };
			                // 地址赋值
			                var arr = ['province', 'city', 'county', 'province_name', 'city_name', 'county_name', 'address'];
			                for(var i in arr) {
			                    if((ads_data[arr[i]] || null) != null) {
			                        temp_ads[arr[i]] = ads_data[arr[i]];
			                    }
			                }
							// 更新地址数据
			                upd_data['address_data'] = temp_ads;
			                this.setData(upd_data);
			            } else {
			                if (app.globalData.is_login_check(res.data)) {
			                    app.globalData.showToast(res.data.msg);
			                } else {
			                    app.globalData.showToast(this.$t('common.sub_error_retry_tips'));
			                }
			            }
			        },
			        fail: () => {
			            uni.hideLoading();
			            app.globalData.showToast(this.$t('common.internet_error_tips'));
			        },
			    });
			},
			
			// 协议开启弹层
			popup_xieyi_event(e) {
			    if(!app.globalData.is_single_page_check()) {
			        return false;
			    }
			    this.setData({
			        popup_xieyi_status: true
			    });
			},
			
			// 协议弹层关闭
			popup_xieyi_close_event(e) {
			    this.setData({
			        popup_xieyi_status: false
			    });
			},
			
			// 协议改变
			agreement_change(e) {
				this.setData({
				   agreement_status:!this.agreement_status
				});
			},
			
			// 同意该协议
			xieyi_enter_confirm_event(){
				this.setData({
				    agreement_status: true,
					popup_xieyi_status: false
				});
			},
			open_ragion(e) {
				// 先判断是否自动识别省市区，如果是，则不允许选择
				// 先判断是否已经定位到经纬度，若有，则可以选择省市区，否则先提示
				var temp_address = this.address_data || {};
				if(this.is_user_address_discern == 1 && (temp_address['lng'] || null) == null)
				{
					app.globalData.showToast(this.$t('fengcheche.select_location_tips'));
				}else{
					this.setData({
					    region_picker_show: true,
					});
				}
			},
			close_event(data) {
			    this.setData({
			        region_picker_show: false,
			    });
			},
			region_event() {
			    let data = uni.getStorageSync(app.globalData.data.cache_region_picker_choice_key) || {};
			    if((data.province || null) == null) {
			        data.province = {};
			    }
			    if((data.city || null) == null) {
			        data.city = {};
			    }
			    if((data.areal || null) == null) {
			        data.areal = {};
			    }
			    this.setData({
			        province_id: data.province.id || null,
			        city_id: data.city.id || null,
			        county_id: data.areal.id || null,
			        province_name: data.province.name || '',
			        city_name: data.city.name || '',
			        county_name: data.areal.name || '',
			    });
				// 手动选择位置后清除位置缓存信息，同时清除lng/lat
				this.choose_user_location_remove();
				this.done_regin_baidu(this.province_name+this.city_name+this.county_name);
			},
			yxblur(e){
				//console.log(e);
				var value = e.detail.value || '';
				this.done_regin_baidu(this.province_name+this.city_name+this.county_name+this.value);
			},
			// 手动选择后，根据省市区调用百度接口得到地址解析经纬度，在输入详细地址好后，再次调用该接口--暂未实现
			done_regin_baidu(str=''){
				return false;
				/*uni.showLoading({
				    title: this.$t('common.processing_in_text'),
				    mask: true,
				});*/
				uni.request({
				    url: app.globalData.get_request_url('regionbaidu', 'index', 'classinfo'),
				    method: 'POST',
				    data: {'str': str},
				    dataType: 'json',
				    success: (res) => {console.log(res);
				        uni.hideLoading();
				        if (res.data.code == 0) {
				            var temp_address = this.address_data || {};
				            var temp_data = res.data.data;
							if(temp_data)
							{
								// 将address_data中的可能存在的lng改为解析到的结果
								temp_address['lng'] = temp_data.lng || null;
								temp_address['lat'] = temp_data.lat || null;
								this.setData({
									address_data: temp_address
								});
								
								if(temp_address['lng'])
								{
									const locationInfo = `定位信息：${temp_address.lat}, ${temp_address.lng}`;
									this.locationInfo = locationInfo;
								}
							}
				        } else {
				            app.globalData.showToast(res.data.msg);
				        }
				    },
				    fail: () => {
				        uni.hideLoading();
				        app.globalData.showToast(this.$t('common.internet_error_tips'));
				    },
				});
			}
        },
    };
</script>
<style>
    @import './form.css';
</style>
